package com.ruoyi.project.pandian.record.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.pandian.record.domain.PdRecord;
import com.ruoyi.project.pandian.record.service.IPdRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点记录Controller
 * 
 * @author ruoyi
 * @date 2023-04-13
 */
@Controller
@RequestMapping("/pandian/record")
public class PdRecordController extends BaseController
{
    private String prefix = "pandian";

    @Autowired
    private IPdRecordService pdRecordService;

    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询盘点记录列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PdRecord pdRecord)
    {
        startPage();
        List<PdRecord> list = pdRecordService.selectPdRecordList(pdRecord);
        return getDataTable(list);
    }

    /**
     * 导出盘点记录列表
     */
    @Log(title = "盘点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PdRecord pdRecord)
    {
        List<PdRecord> list = pdRecordService.selectPdRecordList(pdRecord);
        ExcelUtil<PdRecord> util = new ExcelUtil<PdRecord>(PdRecord.class);
        return util.exportExcel(list, "盘点记录数据");
    }

    /**
     * 新增盘点记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存盘点记录
     */
    @Log(title = "盘点记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PdRecord pdRecord)
    {
        return toAjax(pdRecordService.insertPdRecord(pdRecord));
    }

    /**
     * 修改盘点记录
     */
    @GetMapping("/edit/{pdGuid}")
    public String edit(@PathVariable("pdGuid") String pdGuid, ModelMap mmap)
    {
        PdRecord pdRecord = pdRecordService.selectPdRecordByPdGuid(pdGuid);
        mmap.put("pdRecord", pdRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存盘点记录
     */
    @Log(title = "盘点记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PdRecord pdRecord)
    {
        return toAjax(pdRecordService.updatePdRecord(pdRecord));
    }

    /**
     * 删除盘点记录
     */
    @Log(title = "盘点记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pdRecordService.deletePdRecordByPdGuids(ids));
    }
}
